Fix RequestsCookieJar MutableMapping mismatch#7251
Open
EthicalCha0s wants to merge 1 commit intopsf:mainfrom
Open
Fix RequestsCookieJar MutableMapping mismatch#7251EthicalCha0s wants to merge 1 commit intopsf:mainfrom
EthicalCha0s wants to merge 1 commit intopsf:mainfrom
Conversation
Author
|
Quick follow-up: after installing the dev test dependencies from
So the earlier big batch of errors was down to missing test dependencies in my local environment, not this change. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
RequestsCookieJarcurrently inherits from bothCookieJarandMutableMapping, but it does not actually satisfy theMutableMappingcontract.
CookieJar.__iter__yieldsCookieobjects, whileMutableMappingexpectsiteration over keys. That means
RequestsCookieJarcan report itself as aMutableMappingeven though code written against that interface will fail.This change removes the
MutableMappingbase class fromRequestsCookieJarwhile keeping its existing dict-like convenience methods.What changed
MutableMappingfromRequestsCookieJar's base classesget,set,keys,items, etc.)MutableMapping:__contains__update__eq__RequestsCookieJaris no longer treatedas a
MutableMappingWhy this approach
I considered changing iteration to yield keys instead, but that would also
change the current behavior of iterating over a cookie jar, which today yields
Cookieobjects.Removing the incorrect ABC inheritance seemed safer than changing iteration
semantics.
Testing
Ran a focused local test slice covering the changed behavior:
tests/test_requests.py -k 'prepared_copy or cookie_jar_is_not_a_mutable_mapping or cookie_as_dict or cookie_parameters or cookie_duplicate_names'Result:
I also compared a full local test run on a clean clone versus this branch.
Clean clone:
Patched branch:
The extra passing test is the new regression test. The 196 errors were already
present on a clean clone in my environment.
Closes #7228